﻿using Microsoft.AspNetCore.Mvc;
using MQTTnet.Server;
using MqttService.Code;

namespace MqttService.Controllers
{
    [ApiController]
    [Route("[controller]/[action]")]
    public class TestController : Controller
    {
        private readonly ILogger<TestController> _logger;
        private readonly IMqttInterface _mqttService;
        private readonly IMqttManager _mqttManager;
        public TestController(ILogger<TestController> logger, IMqttInterface mqttService, IMqttManager mqttManager)
        {
            _logger = logger;
            _mqttService = mqttService;
            _mqttManager = mqttManager;
        }
        [HttpGet]
        public bool Get(string topic,string data)
        {  
            _mqttManager.PublishData(topic, data);
            return true;
        }

        [HttpGet]
        public async Task<bool> start()
        {
            await _mqttService.StartAsync();
            return true;
        }
        [HttpGet]
        public async Task<bool> stop()
        {
            await  _mqttService.StopAsync();
            return true;
        }
    }
}
